<?php

/**
 * @author @author Samrat Khan & Sadik Sarfaraz - Apr 13, 2013
 */

    require('top.inc.php');
    $formLoad = new Form();
?>
<?php
if(isset($_SESSION['user']) && $_SESSION['user']['utype'] == 1 || $_SESSION['user']['utype'] == 2) {
    if(isset($_POST['addEmployee'])) {
        $query = "INSERT INTO employee ( employeename, employeecell, designation, warehouse_id, inserteddate ) VALUES ( :employeename, :employeecell, :designation, :warehouse_id, :inserteddate )";
        $query_params = array(
            ':employeename' => $_POST['employeename'],
            ':employeecell' => $_POST['employeecell'],
            ':designation' => $_POST['designation'],
            ':warehouse_id' => $_POST['warehouse_id'],
            ':inserteddate' => date('Y-m-d H:i:s')
        );
        
        try {
            $stmt = $db->prepare($query);
            $result = $stmt->execute($query_params);
        } catch (PDOException $ex) {
            die("Failed to run query: " . $ex->getMessage());
        }
        if($result) {
            echo $msg['37'];
        }
    } else {
?>
<form class="form-horizontal" action="" method="post" id="addEmployee">
    <div class="control-group">
        <label class="control-label" for="employeename"><?php echo $employee['employeename']; ?></label>
        <div class="controls">
            <?php echo $formLoad->textField('employeename', "span2", "", $employee['employeename']); ?>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label" for="employeecell"><?php echo $employee['employeecell']; ?></label>
        <div class="controls">
            <?php echo $formLoad->textField('employeecell', "span2", "", $employee['employeecell']); ?>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label" for="designation"><?php echo $employee['designation']; ?></label>
        <div class="controls">
            <?php echo $formLoad->textField('designation', "span2", "", $employee['designation']); ?>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label" for="warehouse_id"><?php echo $employee['warehouse_id']; ?></label>
        <div class="controls">
            <select name="warehouse_id">
                <?php echo getWarehousesCode($db); ?>
            </select>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label" for="inputEmployee">&nbsp;</label>
        <div class="controls"><input class="btn btn-primary" type="submit" value="Add Employee" name="addEmployee" /></div>
    </div>
</form>
<?php
    }
} else {
    header("Location: login.php");
}
?>
<?php
    include ('bottom.inc.php');
?>